//
//  SecondViewController.m
//  AnalyticsSample
//
//  Copyright 2010 Google Inc. All rights reserved.
//

#import "SecondViewController.h"
#import "GANTracker.h"


@implementation SecondViewController

@synthesize saleConfirmation;

- (void)viewDidLoad {
  [super viewDidLoad];

  //track this pageview
  NSError *error;
  if (![[GANTracker sharedTracker] trackPageview:@"/SecondViewController"
                                       withError:&error]) {
    NSLog(@"Error: %@", error);
  }
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

#pragma mark -
#pragma mark ClickActions

- (IBAction)buyDandyHat:(id)sender {
  [self.saleConfirmation setText:@"My, that's a dandy hat!"];

  // track this action
  NSError *error;
  if (![[GANTracker sharedTracker] trackEvent:@"SecondViewController"
                                       action:@"boughtHat"
                                        label:@"dandyHat"
                                        value:10
                                    withError:&error]) {
    NSLog(@"Error: %@", error);
  }
}

- (IBAction)buyDapperHat:(id)sender {
  [self.saleConfirmation setText:@"Wow, someone looks dapper!"];

  // track this action
  NSError *error;
  if (![[GANTracker sharedTracker] trackEvent:@"SecondViewController"
                                       action:@"boughtHat"
                                        label:@"dapperHat"
                                        value:20
                                    withError:&error]) {
    NSLog(@"Error: %@", error);
  }
}

- (IBAction)buyWizardHat:(id)sender {
  [self.saleConfirmation setText:@"Accio hat!"];

  // track this action
  NSError *error;
  // Wizard hats are free!
  if (![[GANTracker sharedTracker] trackEvent:@"SecondViewController"
                                       action:@"boughtHat"
                                        label:@"wizardHat"
                                        value:0
                                    withError:&error]) {
    NSLog(@"Error: %@", error);
  }
}

- (void)dealloc {
  self.saleConfirmation = nil;
  [super dealloc];
}


@end
